﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using LearnThemselvesEffectively.Classes;

namespace LearnThemselvesEffectively
{
    /// <summary>
    /// Interaction logic for frmWordsTranslation.xaml
    /// </summary>
    public partial class frmWordsTranslation : Window
    {
        Point moDownPoint;
        bool moAllowMoveWindow;
        private TranslationCore moTranslationCore;

        public frmWordsTranslation()
        {
            InitializeComponent();
            txtInsertWord.Focus();
            if (GlobalSupportModele.TranslationWindowModule == GlobalSupportModele.eTranslationWindowModule.Learn)
                moTranslationCore = new LearnCore(ProxyOption.SelectedState);
            else
                moTranslationCore = new ExamCore(ProxyOption.SelectedState);
        }

        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            moDownPoint = new Point(Mouse.GetPosition(this).X, Mouse.GetPosition(this).Y);
            moAllowMoveWindow = true;
        }

        private void StackPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            moAllowMoveWindow = false;
        }

        private void StackPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (moAllowMoveWindow == false)
            {
                return;
            }
            Point location = new Point(
                this.Left + e.GetPosition(this).X - moDownPoint.X,
                this.Top + e.GetPosition(this).Y - moDownPoint.Y);
            this.Left = location.X;
            this.Top = location.Y;
        }

        private void xBackgroud_CloseCommand(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnFinish_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(moTranslationCore.WarningMessage, "Finish session warning", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                GlobalSupportModele.OpenNewFrameCloseOwner(new frmRootUI(), this);
            }
        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            NextWordCHeck();
        }

        private void txtInsertWord_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                NextWordCHeck();                
            }
        }
        
        private void NextWordCHeck()
        {
            if (GlobalSupportModele.TranslationWindowModule == GlobalSupportModele.eTranslationWindowModule.Learn)
            {
                (moTranslationCore as LearnCore).CheckIfLearned(txtInsertWord.Text);
            }
            else
            {
                throw new Exception("Not implemented check test!");
            }
            moTranslationCore.NextWord();
            if (GlobalSupportModele.SessionState == GlobalSupportModele.eSessionState.Finished)
            {
                throw new Exception("Not implemented!");
            }
        }
    }
}
